
const context = require.context('./', true, /\.js$/,);

// API集合对象
const API = {};

context.keys().forEach(name => {
    //遍历到index.js时结束
    if (name.startsWith("./index")) {
        return false;
    }
    let pathArr = name.split('/');
    // 处理模块接口
    if (pathArr.length > 2) {
        let moduleKey = pathArr[1],
            key = pathArr[2].slice(0, pathArr[2].lastIndexOf('.'));
        if (!API[moduleKey]) API[moduleKey] = {};
        Object.assign(API[moduleKey], {
            [key]: context(name).default || context(name)
        })
    } else {
        // 处理通用接口
        let moduleKey = name.slice(2, name.lastIndexOf('.'));
        Object.assign(API, {
            [moduleKey]: context(name).default || context(name)
        })
    }

})
export default API;